/**
 * OOB专用JS方法
 */
var IdWidth = 20;
var NumberWidth = 120;//单号
var UserNameWidth = 85;//姓名
var DateWidth = 100;//日期
var TimeWidth = 80;//时间
var DateTimeWidth = 135;//日期时间
var AuditStatusWidth = 90;//审核状态
var FactoryWidth = 85;//厂别
var ShiftWidth = 90;//班次
var ShiftClassWidth = 130;//已分配班次
var MatnrWidth = 130;//料号
var MachineWidth = 100;//机台
var TypeWidth = 110;//成型/组装
var DescriptionWidth = 110;//品名
var QtyWidth = 90;//数量
var StatusWidth = 90 ;//状态
var RemarkWidth = 130;//备注
var PerWith = 300;//百分比进度条
var BasicsTypeWidth =  100;//基础类型
var BasicsNameWidth = 300;//基础类型名称
var TemplateTypeWidth = 230;//模板类型
var TemplateNameWidth = 160;//模板名称
var CycleWidth = 100;//模板项目频率
var IPWidth = 100;//IP
var MailWidth = 200;//邮件
var MobileWidth = 100;//电话
var AgeWidth = 100;//年龄
var SexWidth = 100;//性别
var PositionNameWidth = 100;//职位
var RoleNameWidth = 100;//职位
var DepartmentNameWidth = 100;//职位
var AccountWidth = 100;//账户
var QualitativeWidth = 100;//检验定性
var ResultWidth = 100;//判定结果
var ReworkQtyWidth = 80;//工单数量
var ModelWidth = 80;//穴号
var LotQqtyWidth = 50;//批次
var StageWidth = 80;//阶段
var RowNumberWidth = 110;//表格编辑操作
var LogContentWidth = 100;//表格编辑操作
var IsSteakWidth = 90;//是否排配
var CustomerWidth = 90;//客户
var CustomerAddressWidth = 140;//客户地址
var SourceWidth = 80;//数据来源
var StrictWidth = 80;//加严正常
var CompanyWidth = 120;//责任单位

//页面加载完成
$(function(){
    //日期控件
    $('[data-datetime]').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'yyyy-MM-dd',lang:'auto'});
    });
    //日期控件
    $('[data-datepickers-hys]').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'HH:mm:ss',lang:'auto'});
    });
    //日期控件
    $('[data-tiem]').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'HH:mm',lang:'auto'});
    });
    //时间段选择
    $('#start_date').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'yyyy-MM-dd',lang:'auto'});
    });
    $('#end_date').on('click', function () {
        WdatePicker({ el:this,minDate:'#F{$dp.$D(\'start_date\')}', dateFmt: 'yyyy-MM-dd',lang:'auto'});
    });
    //时间段选择 月份
    $('#start_month').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'yyyy-MM',lang:'auto'});
    });
    $('#end_month').on('click', function () {
        WdatePicker({ el:this,minDate:'#F{$dp.$D(\'start_month\')}', dateFmt: 'yyyy-MM',lang:'auto'});
    });
    //时间段选择
    $('#start_datetime').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'yyyy-MM-dd H:m:s',lang:'auto'});
    });
    $('#end_datetime').on('click', function () {
        WdatePicker({ el:this,minDate:'#F{$dp.$D(\'start_datetime\')}', dateFmt: 'yyyy-MM-dd H:m:s',lang:'auto'});
    });
    // 首件检验时间 H:I

    $('[data-hi]').on('click', function () {
        WdatePicker({ el:this,dateFmt: 'HH:mm',lang:'auto'});
    });
    //查看tips
    $("body").on("mouseover","[layer-tips]",function () {
        var tips = $(this).attr('layer-tips');
        tips = '<div style="word-wrap: break-word;word-break: break-all;">'+tips+'</div>';
        layer.tips(tips, this, {
            tips: [1, '#3595CC'],
            time: 0
        });
    });
    //复制tips
    $("body").on("click","[layer-tips]",function () {
        var tips = $(this).attr('layer-tips');
        layer.open({
            type: 1,
            area: ['500px', '300px'],
            shadeClose: true, //开启遮罩关闭
            content: '<div style="padding:30px;word-wrap: break-word;word-break: break-all;">'+tips+'</div>'
        });
    });
    //关闭tips
    $("body").on("mouseout","[layer-tips]",function () {
        layer.closeAll('tips');
    });
    //数据导出
    $("[pt-export]").on("click",function () {
        var dg = $('#'+$(this).attr("pt-export"));
        if(dg.length <= 0){
            console.log("没找到需要导出的表格");
            return;
        }
        if((typeof dg.bootstrapTable) == "undefined"){
            console.log("找到的表格不是bootstrapTable对象");
            return;
        }
        var op = dg.bootstrapTable("getOptions");
        var url = op.url;
        var col = op.columns;
        var data = op.queryParams({});
        //获取页面标题
        var title = dg.attr("table-title");
        if(typeof title == "undefined" || title == ""){
            title = "导出数据";
        }
        //精简columns
        var new_col = [];
        for(var i=0;i<col.length;i++){
            var cc = [];
            for(var j=0;j<col[i].length;j++){
                if(typeof col[i][j] == "undefined"){
                    continue;
                }
                if(col[i][j]['field'] == ""){
                    continue;
                }
                if(col[i][j]['field'] == "id"){
                    continue;
                }
                if(!col[i][j].visible){
                    continue;
                }
                var c = {};
                c.title = col[i][j]["title"];
                c.field = col[i][j]["field"];
                c.rowspan = col[i][j]["rowspan"];
                c.colspan = col[i][j]["colspan"];
                if(typeof col[i][j]["formatter"] != "undefined"){
                    var funcName = col[i][j]["formatter"]['name'];
                    if (funcName == "BasicsTypeTxt") {
                        c.type = "BasicsType";
                    } else if (funcName == "WhiteNightTxt") {
                        c.type = "WhiteNight";
                    } else if (funcName == "AuditTxt") {
                        c.type = "Audit";
                    } else {
                        c.type = "string";
                    }
                } else {
                    c.type = "string";
                }
                cc.push(c);
            }
            new_col.push(cc);
        }
        var cols = JSON.stringify(new_col);
        var reg = /(\w+)\/(\w+)\/(\w+).*/ig;
        var r = reg.exec(url);
        var m = r[1];
        var c = r[2];
        var f = r[3];
        data.offset = 0;
        data.limit = 999999999;
        data.eee_m = m;
        data.eee_c = c;
        data.eee_f = f;
        data.eee_l = cols;
        data.eee_t = title;
        //定义一个form表单
        var form = $("<form>");
        form.attr("style", "display:none");
        form.attr("target", "_blank");
        form.attr("method", "post");
        form.attr("action", "/oob/bus/export_data");
        //遍历
        for (var key in data) {
            var input = $("<input>");
            input.attr("type", "hidden");
            input.attr("name", key);
            input.attr("value", data[key]);
            form.append(input);
        }
        //将表单放置在web中
        $("body").append(form);
        //表单提交
        form.submit();
    });
    
    //附件管理
    $('body').on('click','[upload-file]',function () {
        var attachment = $(this).attr('data-attachment');
        alert(1);
        oob.uploadView(attachment, "no", '');
    });


});

(function (window) {
    /* 提交数据到服务器 */
    var ajax = function(option){

        //弹出load
        var index = layer.load(2 ,{ icon: 2 ,shade: 0.1 });

        return new Promise(function(resolve,reject){
            $.ajax(option)
                .done(function(data, textStatus, jqXHR){
                    resolve(data);
                })
                .fail(function(jqXHR, textStatus, errorThrown){

                    var text = '';
                    if(jqXHR.status == 0) {
                        text = "服务器连接失败！";
                    } else if(jqXHR.status == 403) {
                        text = "没有权限,请联系管理员！";
                    }else if (jqXHR.status == 500) {
                        var html = jqXHR.responseText;
                        var reg = /<h1>([^<]*)</;
                        var res = reg.exec(html);
                        if(res){
                            text = res[1];
                        } else {
                            text = "服务器内部错误,请联系管理员！";
                        }
                    } else {
                        text = "未知错误,请联系管理员！";
                    }

                    layer.msg("操作失败："+text, {icon: 5});

                    reject(jqXHR);
                })
                .always(function(){
                    layer.close(index);
                });
        });
    };

    /* 提交数据到服务器 */
    var ajaxIframe = function(option){

        //弹出load
        var index = parent.layer.load(2 ,{ icon: 2 ,shade: 0.1 });

        return new Promise(function(resolve,reject){
            $.ajax(option)
            .done(function(data, textStatus, jqXHR){
                resolve(data);
            })
            .fail(function(jqXHR, textStatus, errorThrown){

                var text = '';
                if(jqXHR.status == 0) {
                    text = "服务器连接失败！";
                } else if(jqXHR.status == 403) {
                    text = "没有权限,请联系管理员！";
                }else if (jqXHR.status == 500) {
                    var html = jqXHR.responseText;
                    var reg = /<h1>([^<]*)</;
                    var res = reg.exec(html);
                    if(res){
                        text = res[1];
                    } else {
                        text = "服务器内部错误,请联系管理员！";
                    }
                } else {
                    text = "未知错误,请联系管理员！";
                }

                parent.layer.msg("操作失败："+text, {icon: 5});

                reject(jqXHR);
            })
            .always(function(){
                parent.layer.close(index);
            });
        });
    };

    /* 弹出提示信息 */
    function show(data,cb){
        if(typeof data == 'string'){
            layer.alert(data, { icon: 6, time: 3000, end: cb });
        } else if(typeof data == 'object'){
            if(data.code == 0){
                if(data.msg){
                    layer.msg(data.msg, { icon: 1, time: 3000, end: cb });
                } else {
                    layer.msg('操作成功', { icon: 1, time: 3000, end: cb });
                }
            } else {
                layer.alert(data.msg, { icon: 2, time: 0, end: cb});
            }
        }
    };

    /* 弹出提示信息 */
    function showIframe(data,cb){
        if(typeof data == 'string'){
            parent.layer.alert(data, { icon: 6, time: 3000, end: cb });
        } else if(typeof data == 'object'){
            if(data.code == 0){
                if(data.msg){
                    parent.layer.msg(data.msg, { icon: 1, time: 3000, end: cb });
                } else {
                    parent.layer.msg('操作成功', { icon: 1, time: 3000, end: cb });
                }
            } else {
                parent.layer.alert(data.msg, { icon: 2, time: 0, end: cb});
            }
        }
    };

    /* 初始化指定模板为选择员工 */
    function set_user(tpl,$scope) {

        $(tpl).fSuggest({
            url: "/admin/bus/user_lst",
            idField: "id",
            textField: "name",
            queryParams: function (params) {
                params.shift = $scope.model.shift;
                return params;
            },
            columns: [
                { "field": "id", title: "#",width: 50, visible:false },
                { "field": "name", title: "姓名",width: 80 },
                { "field": "degree", title: "熟练度",width: 80 },
            ]
        });
    };

    /* 初始化指定模板为选择员工 */
    function set_users(tpl,$scope) {

        $(tpl).fSuggest({
            url: "/admin/bus/user_lst",
            idField: "id",
            textField: "name",
            queryParams: function (params) {
                params.shift = $scope.model.shift;
                return params;
            },
            columns: [
                { "field": "id", title: "#",width: 50, visible:false },
                { "field": "name", title: "姓名",width: 80 },
            ]
        });
    };

    // $("#tpl_table").fSuggest({
    //     width:400,
    //     url:"/iqc/bus/lst_supplier",
    //     idField:"vendor_name",
    //     textField:"vendor_name",
    //     queryParams: function (params) {
    //         params.item = $("#tpl_table").attr('item');
    //         return params;
    //     },
    //     columns: [
    //         {"field":"vendor_name",title:"Supplier"},
    //     ]
    // });

    /* 初始化指定模板为选择模板 */
    function set_template(tpl,type) {
        $(tpl).fSuggest({
            url: "/qc/bus/template_lst?type="+type+"&key=",
            idField: "id",
            textField: "name",
            columns: [
                { "field": "id", title: "#",width: 50, visible:false },
                { "field": "name", title: "抽样规则",width: 80 },
                { "field": "remark", title: "备注",width: 80 },
            ]
        });
    };

    /* bootstraptable的行操作函数 */
    function row_op() {
        return "<a href='###'><i class='fa fa-plus'></i></a>&nbsp;&nbsp;<a href='###'><i class='fa fa-trash'></i></a>";
    };

    /* bootstraptable 补齐行数 */
    function pad_row(dg, count) {
        var data = $(dg).bootstrapTable("getData");
        var len = data.length;
        for (var i = len; i < count; i++) {
            $(dg).bootstrapTable("append", { number: i + 1 });
        }
    };

    //是否是平板浏览
    function isPad() {
        if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
            return true;
        }else{
            return false;
        }
    }

    /*
     获取当前页面所在的父页面iframe
     */
    function getCurrentIFrame() {
        var ifrs = parent.document.getElementsByTagName('iframe');
        console.log(ifrs);
        for (var i = 0, j = ifrs.length; i < j; i++) {
            if (ifrs[i].contentWindow == window) {
                return ifrs[i];
            }
        }
    }

    //关闭当前tab
    function closeTab(id){
        if(isPad())
        {
            window.history.go(-1);
        }
        else
        {
            if (!id) {
                // var iframe = func.getCurrentIFrame();
                var iframe = getCurrentIFrame();
                if (iframe) {
                    id = iframe.id;
                    id = id.substr(1);
                } else {
                    return;
                }
            }

            var ti = $("a.J_menuTab[data-id='" + id + "'] i", window.top.document);
            ti.trigger('click');
        }
    }


    /*
    * 产生guid
    * */
    function guid() {
        function S4() {
            return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
        }
        return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
    }

    //上传文件界面  isLook=yes，查看文件，，不传或传no，上传文件
    var uploadView = function(rel, isLook, key){
        var title = "";
        if(isLook == 'yes'){
            title = "查看文件";
        }else{
            isLook = 'no';
            title = "上传文件";
        }
        layer.open({
            title: title,
            type: 2,
            area: ['700px', '70%'],
            fix: true,
            maxmin: false,
            content: '/bus/upload/index?rel=' + rel + '&is_look=' + isLook + '&key=' +key,
            yes:function (ee) {
                console.log(ee);
            }
        });
    };

    function accAdd(arg1,arg2){
        var r1,r2,m;
        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
        m=Math.pow(10,Math.max(r1,r2))
        // return (arg1*m+arg2*m)/m
        return Math.round(((arg1*m+arg2*m)/m)*100000)/100000;
    }

    function toFloat2(s) {
        if(s === null || s === '' || typeof(s) === 'undefined'){
            return null;
        }
        s = parseFloat(s);
        if(isNaN(s)){
            return null;
        }
        return s;
    }

    //计算不良 返回1 红色，返回2 黄色，返回0 无色
    var judgeMeas = function(row, field){
        var item = row['number'];
        var spec = row['specs'];
        var max = row['max'];
        var min = row['min'];
        var val = row[field];
        if(!item){
            return 0;
        }
        if(!val){
            return 0;
        }
        if(typeof(val) === 'string' && val.toLowerCase() == "pass") {
            return 0;
        }
        if(typeof(val) === 'string' && val.toLowerCase() == "fail") {
            return 1;
        }
        if(spec == null) {
            return 0;
        }
        if(val == null) {
            return 1;
        }
        spec = Math.abs(toFloat2(spec));
        max = toFloat2(max);
        min = toFloat2(min);
        val = Math.abs(toFloat2(val));
        //上下公差为空时判断
        if(max == null && min == null && val > spec){
            return 1;
        }
        //增加 大小值变换
        var val_max = accAdd(spec,max);
        var val_min = accAdd(spec,min);
        if(max != null &&  val_max == val){
            return 2;
        }
        if(min != null &&  val_min == val){
            return 2;
        }
        if(val_min != 0 && val_max != 0){
            if(val_min > val_max){
                var val_median = val_max;
                val_max = val_min;
                val_min = val_median;
            }
        }
        // console.log(1111);
        // console.log([val_min,val_max]);
        // console.log(val);
        if(max != null &&  val_max < val){
            return 1;
        }
        if(min != null &&  val_min > val){
            return 1;
        }

        return 0;
    };

    //格式化单元格显示
    function formatCell(value, row, index, field){
        var result_data = judgeMeas(row, field);
        if(result_data == 1){
            return { classes: 'red-bg' }

        }else if(result_data == 2){
            return { classes: 'yellow-bg' }
        } else {
            return { classes: ''}
        }
    };

    //格式化单元格编辑显示
    function formatEditCell(row, index, value, field){
        var data1 = $(field['dg']).bootstrapTable("getData");
        var result_data = judgeMeas(data1[row], field['field']);
        if(result_data == 1){
            $(field['dg']).find("tbody tr:eq("+(row)+") td:eq("+(index-1)+")").removeClass();
            $(field['dg']).find("tbody tr:eq("+(row)+") td:eq("+(index-1)+")").addClass("red-bg");
        }else if(result_data == 2){
            $(field['dg']).find("tbody tr:eq("+(row)+") td:eq("+(index-1)+")").removeClass();
            $(field['dg']).find("tbody tr:eq("+(row)+") td:eq("+(index-1)+")").addClass("yellow-bg");
        }else {
            $(field['dg']).find("tbody tr:eq("+(row)+") td:eq("+(index-1)+")").removeClass();
        }
    };

    //type 是检验员/量测室，data_type和data_val为计算公式和值
    function formCalculation(type,data_type,data_val){
        if(data_val == null || data_val == ''){
            oob.show({code:-1,msg:"项目号不能为空"});
            return false;
        }
        var data = [];
        if(type == '尺寸检验(检验员)'){
            data = $('[data-title="尺寸检验(检验员)"]').bootstrapTable("getData");
        }else {
            data = $('[data-title="尺寸检验(量测室)"]').bootstrapTable("getData");
        }
        var data_length = data.length;
        //AB
        if(data_type == 'AB'){
            if(!$.isNumeric(data_val)){
                oob.show({code:-1,msg:"请输入正确的项目号"});
                return false;
            }
            //检验员行数据
            var data_col = data[data_val-1];
            if(typeof data_col['specs'] == 'undefined' || data_col['specs'] == null){
                oob.show({code:-1,msg:"没有可计算的穴号"});
                return false;
            }
            for (i=1;i<21;i++){
                if (!(data_col['sample'+i] == null || data_col['sample'+i] == 0)){
                    data[data_val]['sample'+i] = (Math.abs(parseFloat(data_col['sample'+i]) - parseFloat(data_col['specs']))*2).toFixed(3);
                }
            }
        }

        //CZ
        if(data_type == 'CZ'){
            //自定义数组对象
            var max_min_arr = [];
            for (j=1;j<21;j++){
                max_min_arr.push([0,0]);
            }
            var data_val_arr = data_val.split("-");
            var data_val_arr_length = data_val_arr.length;
            var index_val = 0;
            var new_num = 0;
            if (data_val_arr_length < 2){
                oob.show({code:-1,msg:"项目号异常"});
            } else if(data_val_arr_length == 2){
                //获取计算行数据的索引
                let first_nums = data_val_arr[0]-1;
                let second_nums = data_val_arr[1]-1;
                if(first_nums > second_nums || data_length < second_nums){
                    oob.show({code:-1,msg:"项目号填写不正确"});
                    return false;
                }
                //当前索引
                index_val = second_nums;
                for (var i=first_nums;i<=second_nums;i++){
                    if(typeof data[i]['specs'] == 'undefined' || data[i]['specs'] == null){
                        oob.show({code:-1,msg:"规格不能为空"});
                        return false;
                    }
                    for (var j=1;j<21;j++){
                        if (!(data[i]['sample'+j] == null || data[i]['sample'+j] == 0)){
                            // 计算样品与规格的绝对差值
                            new_num = parseFloat(data[i]['sample'+j]) - parseFloat(data[i]['specs']);
                            if(i==first_nums){

                                max_min_arr[j-1][0] = new_num;
                                max_min_arr[j-1][1] = new_num;
                            }else {
                                if(new_num < max_min_arr[j-1][0]){
                                    max_min_arr[j-1][0] = new_num;
                                }
                                if(new_num > max_min_arr[j-1][1]){
                                    max_min_arr[j-1][1] = new_num;
                                }
                            }
                        }
                    }

                }
            }else {
                var data_val_arr = data_val_arr.filter(s => $.trim(s).length > 0);
                var data_val_arr_length = data_val_arr.length;

                index_val = 0;
                for (i=0;i<data_val_arr_length;i++){
                    if(i > 0 && (data_val_arr_length[i-1] > data_val_arr_length[i] || data_length < data_val_arr_length[i])){
                        oob.show({code:-1,msg:"项目号填写不正确"});
                        return false;
                    }
                    index_val = data_val_arr[i]-1;
                    if(typeof data[index_val]['specs'] == 'undefined' || data[index_val]['specs'] == null){
                        oob.show({code:-1,msg:"规格不能为空"});
                        return false;
                    }

                    for (var j=1;j<21;j++){
                        if (!(data[index_val]['sample'+j] == null || data[index_val]['sample'+j] == 0)){
                                // 计算样品与规格的绝对差值
                                new_num = parseFloat(data[index_val]['sample'+j]) - parseFloat(data[index_val]['specs']);

                                if(i==0){
                                    max_min_arr[j-1][0] = new_num;
                                    max_min_arr[j-1][1] = new_num;
                                }else {
                                    if(new_num < max_min_arr[j-1][0]){
                                        max_min_arr[j-1][0] = new_num;
                                    }
                                    if(new_num > max_min_arr[j-1][1]){
                                        max_min_arr[j-1][1] = new_num;
                                    }
                                }
                        }
                    }
                }
            }
            for (j=1;j<21;j++){
                if (max_min_arr[j-1][1] != null && max_min_arr[j-1][1] != '') {
                    data[index_val+1]['sample' + j] = (max_min_arr[j - 1][1] - max_min_arr[j - 1][0]).toFixed(3);
                }
            }
        }

        //XY
        if(data_type == 'XY'){
            var data_val_arr = data_val.split("-");
            //console.log(data_val_arr);return;
            if(data_val_arr.length != 2){
                oob.show({code:-1,msg:"项目号格式不正确"});
                return false;
            }
            //获取计算行数据的索引
            let first_nums = data_val_arr[0]-1;
            let second_nums = data_val_arr[1]-1;
            //判断当前行是否存在
            if(first_nums > second_nums || data_length < second_nums){
                oob.show({code:-1,msg:"项目号填写不正确"});
                return false;
            }
            var first_val =  data[first_nums];
            var second_val =  data[second_nums];
            if(typeof first_val['specs'] == 'undefined' || first_val['specs'] == null
                || typeof second_val['specs'] == 'undefined' || second_val['specs'] == null){
                oob.show({code:-1,msg:"规格不能为空"});
                return false;
            }
            for(i=1;i<21;i++){
                //只计算有值的数据
                if(!(first_val['sample'+i] == null || first_val['sample'+i] == 0 || second_val['sample'+i] == null || second_val['sample'+i] == 0)){
                    //计算样品 实测值与规格 的差 的平方 开平方*2，赋值
                    data[second_nums+1]['sample'+i] = (Math.sqrt(Math.pow(parseFloat(first_val['sample'+i]) - parseFloat(first_val['specs']),2) + Math.pow(parseFloat(second_val['sample'+i]) - parseFloat(second_val['specs']),2))*2).toFixed(3);
                }
            }
        }

        //C-M M-C M+C 为检验员特有的计算
        if(type == '尺寸检验(检验员)' && ['M+C','M-C','C-M',].indexOf (data_type) != -1){
            var room_data = $('[data-title="尺寸检验(量测室)"]').bootstrapTable("getData");
            var room_data_length = room_data.length;
            if(!$.isNumeric(data_val)){
                oob.show({code:-1,msg:"请输入正确的项目号"});
                return false;
            }
            var is_val = true;
            //检验员行数据
            var data_col = data[data_val-1];
            //匹配到的量测室行数据
            var room_data_col = {};
            //匹配量测室准备数据
            var map_position_arr = [data_col['map_position']+'-X-坐标-mm',data_col['map_position']+'-Y-坐标-mm',data_col['map_position']+'-Z-坐标-mm',data_col['map_position']];
            for (var i=0;i<room_data_length;i++){
                if(map_position_arr.indexOf(room_data[i]['map_position']) != -1){
                    room_data_col = room_data[i];
                    is_val = false;
                    break;
                }
            }
            if(is_val){
                oob.show({code:-1,msg:" 匹配量测室数据失败"});
                return false;
            }
            //console.log(room_data_col);
            //循环更新每个穴号的数据
            for(i=1;i<21;i++){
                if(!(data_col['sample'+i] == null || data_col['sample'+i] == 0 || room_data_col['sample'+i] == null || room_data_col['sample'+i] == 0)){
                    if(data_type == 'M+C'){
                        data[data_val]['sample'+i] = (Math.abs(data_col['sample'+i])+Math.abs(room_data_col['sample'+i])).toFixed(3);
                    }else if(data_type == 'M-C'){
                        data[data_val]['sample'+i] = (Math.abs(room_data_col['sample'+i])-Math.abs(data_col['sample'+i])).toFixed(3);
                    }else if(data_type == 'C-M'){
                        data[data_val]['sample'+i] = (Math.abs(data_col['sample'+i])-Math.abs(room_data_col['sample'+i])).toFixed(3);
                    }
                }
            }
        }
        //更新数据
        if(type == '尺寸检验(检验员)'){
            $('[data-title="尺寸检验(检验员)"]').bootstrapTable("load", data);
        }else {
            $('[data-title="尺寸检验(量测室)"]').bootstrapTable("load", data);
        }

    }
    //小写金额转大写
    function madd(Num){
        part = String(Num).split(".");
        newchar = "";
        for(i=part[0].length-1;i>=0;i--){
            if(part[0].length > 10){
                alert("位数过大，无法计算");//前面如果有验证位数的，此处判断可去掉
                return false;
            }
            tmpnewchar = "";
            perchar = part[0].charAt(i);
            switch(perchar){
                case "0": tmpnewchar="零" + tmpnewchar ;break;
                case "1": tmpnewchar="壹" + tmpnewchar ;break;
                case "2": tmpnewchar="贰" + tmpnewchar ;break;
                case "3": tmpnewchar="叁" + tmpnewchar ;break;
                case "4": tmpnewchar="肆" + tmpnewchar ;break;
                case "5": tmpnewchar="伍" + tmpnewchar ;break;
                case "6": tmpnewchar="陆" + tmpnewchar ;break;
                case "7": tmpnewchar="柒" + tmpnewchar ;break;
                case "8": tmpnewchar="捌" + tmpnewchar ;break;
                case "9": tmpnewchar="玖" + tmpnewchar ;break;
            }
            switch(part[0].length-i-1){
                case 0: tmpnewchar = tmpnewchar +"元" ;break;
                case 1: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break;
                case 2: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break;
                case 3: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break;
                case 4: tmpnewchar= tmpnewchar +"万" ;break;
                case 5: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break;
                case 6: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break;
                case 7: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break;
                case 8: tmpnewchar= tmpnewchar +"亿" ;break;
                case 9: tmpnewchar= tmpnewchar +"拾" ;break;
            }
            newchar = tmpnewchar + newchar;
        }
        if(Num.indexOf(".")!=-1){
            if(part[1].length > 2) {
                part[1] = part[1].substr(0,2)
            }
            for(i=0;i<part[1].length;i++){
                tmpnewchar = "";
                perchar = part[1].charAt(i)
                switch(perchar){
                    case "0": tmpnewchar="零" + tmpnewchar ;break;
                    case "1": tmpnewchar="壹" + tmpnewchar ;break;
                    case "2": tmpnewchar="贰" + tmpnewchar ;break;
                    case "3": tmpnewchar="叁" + tmpnewchar ;break;
                    case "4": tmpnewchar="肆" + tmpnewchar ;break;
                    case "5": tmpnewchar="伍" + tmpnewchar ;break;
                    case "6": tmpnewchar="陆" + tmpnewchar ;break;
                    case "7": tmpnewchar="柒" + tmpnewchar ;break;
                    case "8": tmpnewchar="捌" + tmpnewchar ;break;
                    case "9": tmpnewchar="玖" + tmpnewchar ;break;
                }
                if(i==0)tmpnewchar =tmpnewchar + "角";
                if(i==1)tmpnewchar = tmpnewchar + "分";
                newchar = newchar + tmpnewchar;
            }
        }
        while(newchar.search("零元") != -1){
            newchar = newchar.replace("零零", "零");
            newchar = newchar.replace("零亿", "亿");
            newchar = newchar.replace("亿万", "亿");
            newchar = newchar.replace("零万", "万");
            newchar = newchar.replace("零元", "元");
            newchar = newchar.replace("零角", "");
            newchar = newchar.replace("零分", "");
        }
        if(newchar.charAt(newchar.length-1) == "元" || newchar.charAt(newchar.length-1) == "角"){
            newchar = newchar+"整";
        }
        return newchar;
    }
    //输出
    window.oob = {
        ajax:ajax,
        ajaxIframe:ajaxIframe,
        show:show,
        showIframe:showIframe,
        set_user:set_user,
        madd:madd,
        set_users:set_users,
        set_template:set_template,
        row_op:row_op,
        pad_row:pad_row,
        closeTab:closeTab,
        guid:guid,
        uploadView:uploadView,
        formatCell:formatCell,
        formatEditCell:formatEditCell,
        toFloat2:toFloat2,
        formCalculation:formCalculation,

    };
})(window);
